package com.core.cloudcommon.enums;

/**
 * @author =====Lqj=====
 * @className CloudSystemLoginResultCode
 * @description 云系统登陆响应编号
 * @create 2024/12/17 10:30
 **/
public enum CloudSystemLoginResultCode {

    CODE200001(200001, "云系统登陆参数为空，请检查"),
    CODE200002(200002, "账号未注册或已冻结，请检查"),
    CODE200003(200003, "账号或密码不正确，请检查"),
    CODE200004(200004, "退出登陆参数非法，请检查"),
    CODE200005(200005, "发送登陆验证码参数非法，请检查"),
    CODE200006(200006, "验证码仍然在有效期内，无需重复获取"),
    CODE200007(200007, "手机号不存在或已被冻结，请检查"),
    CODE200008(200008, "验证码已过期或不存在，请重新获取"),
    CODE200009(200009, "验证码不正确，请检查"),
    CODE2000010(2000010, "手机号或者验证码为空，请检查"),

    // 密码安全相关错误码
    CODE200012(200012, "密码不能为空"),
    CODE200013(200013, "密码长度不能少于6位"),
    CODE200014(200014, "密码长度不能超过20位"),
    CODE200015(200015, "密码强度不够：至少6位，必须包含字母和数字"),
    CODE200016(200016, "密码强度不够：至少8位，必须包含大小写字母、数字和特殊字符"),
    CODE200017(200017, "密码过于简单，请使用更复杂的密码"),

    // 登录安全相关错误码
    CODE200018(200018, "账户已被锁定，请稍后重试"),
    CODE200019(200019, "验证码错误次数过多，请重新获取验证码"),
    CODE200020(200020, "IP地址已被锁定，请稍后重试"),
    CODE200021(200021, "访问频率过高，请稍后重试"),
    CODE200022(200022, "Token已过期，请重新登录"),
    CODE200023(200023, "Token刷新失败"),
    CODE200024(200024, "设备信息异常"),
    CODE200025(200025, "并发登录超出限制");

    private final Integer code;
    private final String msg;

    CloudSystemLoginResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // 获取 code 值
    public Integer getCode() {
        return code;
    }

    // 获取 msg 值
    public String getMsg() {
        return msg;
    }

    /**
     * 通过 code 获取枚举项
     */
    public static CloudSystemLoginResultCode getByCode(Integer code) {
        if (code == null) {
            throw new IllegalStateException("响应编码不能为空");
        }
        for (CloudSystemLoginResultCode resultCode : CloudSystemLoginResultCode.values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        throw new IllegalStateException("编码不存请重试输入,不存在的编码：" + code);
    }
}
